package com.bite.springbook.model;

import com.bite.springbook.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result<T> {
    private ResultCodeEnum code;
    private String errMag;
    private T data;

    public static <T> Result<T> nologin(){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.NOLOGIN);
        result.setErrMag("用户未登入");
        return result;
    }

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.SUCCESS);
        result.setErrMag("");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(String errMag){
        Result result = new Result<>();
        result.setErrMag(errMag);
        result.setCode(ResultCodeEnum.FAIL);
        result.setData(null);
        return result;
    }
}
